package com.manage.modules.controller;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.manage.common.annotation.Log;
import com.manage.common.core.controller.BaseController;
import com.manage.common.core.domain.AjaxResult;
import com.manage.common.enums.BusinessType;
import com.manage.modules.vo.TBaseFactoryVo;
import com.manage.modules.bo.TBaseFactoryQueryBo;
import com.manage.modules.bo.TBaseFactoryAddBo;
import com.manage.modules.bo.TBaseFactoryEditBo;
import com.manage.modules.service.ITBaseFactoryService;
import com.manage.common.utils.poi.ExcelUtil;
import com.manage.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * 厂家信息Controller
 *
 * @author wx
 * @date 2021-08-12
 */
@Api(value = "厂家信息控制器", tags = {"厂家信息管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/modules/factory")
public class TBaseFactoryController extends BaseController {

    private final ITBaseFactoryService iTBaseFactoryService;

    /**
     * 查询厂家信息列表
     */
    @ApiOperation("查询厂家信息列表")
    @PreAuthorize("@ss.hasPermi('modules:factory:list')")
    @GetMapping("/list")
    public TableDataInfo<TBaseFactoryVo> list(TBaseFactoryQueryBo bo) {
        startPage();
        List<TBaseFactoryVo> list = iTBaseFactoryService.queryList(bo);
        return getDataTable(list);
    }

    /**
     * 导出厂家信息列表
     */
    @ApiOperation("导出厂家信息列表")
    @PreAuthorize("@ss.hasPermi('modules:factory:export')")
    @Log(title = "厂家信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<TBaseFactoryVo> export(TBaseFactoryQueryBo bo) {
        List<TBaseFactoryVo> list = iTBaseFactoryService.queryList(bo);
        ExcelUtil<TBaseFactoryVo> util = new ExcelUtil<TBaseFactoryVo>(TBaseFactoryVo.class);
        return util.exportExcel(list, "厂家信息");
    }

    /**
     * 获取厂家信息详细信息
     */
    @ApiOperation("获取厂家信息详细信息")
    @PreAuthorize("@ss.hasPermi('modules:factory:query')")
    @GetMapping("/{factoryId}")
    public AjaxResult<TBaseFactoryVo> getInfo(@PathVariable("factoryId") Long factoryId) {
        return AjaxResult.success(iTBaseFactoryService.queryById(factoryId));
    }

    /**
     * 新增厂家信息
     */
    @ApiOperation("新增厂家信息")
    @PreAuthorize("@ss.hasPermi('modules:factory:add')")
    @Log(title = "厂家信息", businessType = BusinessType.INSERT)
    @PostMapping()
    public AjaxResult<Void> add(@RequestBody TBaseFactoryAddBo bo) {
        return toAjax(iTBaseFactoryService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改厂家信息
     */
    @ApiOperation("修改厂家信息")
    @PreAuthorize("@ss.hasPermi('modules:factory:edit')")
    @Log(title = "厂家信息", businessType = BusinessType.UPDATE)
    @PutMapping()
    public AjaxResult<Void> edit(@RequestBody TBaseFactoryEditBo bo) {
        return toAjax(iTBaseFactoryService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除厂家信息
     */
    @ApiOperation("删除厂家信息")
    @PreAuthorize("@ss.hasPermi('modules:factory:remove')")
    @Log(title = "厂家信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{factoryIds}")
    public AjaxResult<Void> remove(@PathVariable Long[] factoryIds) {
        return toAjax(iTBaseFactoryService.deleteWithValidByIds(Arrays.asList(factoryIds), true) ? 1 : 0);
    }
}
